package com.video.controller;

import com.common.domain.dto.SupplierAddDTO;
import com.common.domain.po.Supplier;
import com.common.domain.vo.SupplierListByPageVO;
import com.common.result.Result;
import com.video.service.SupplierService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * @author 路亚
 * @version 0.1
 * @className SupplierController
 * @description
 * @date 2025/1/3 15:41
 * @since jdk11
 */
@RestController
@RequestMapping("/supplier")
@RequiredArgsConstructor
@Slf4j
@Api(tags = "供应商管理")
public class SupplierController {

    private final SupplierService supplierService;

    @PostMapping("/add")
    @ApiOperation("新增供应商")
    public Result add(@RequestBody SupplierAddDTO supplierAddDTO) {
        supplierService.add(supplierAddDTO);
        return Result.success();
    }

    @GetMapping("/listByPage")
    @ApiOperation("分页查询供应商")
    public Result listByPage(String supplierName, Integer page) {
        SupplierListByPageVO result = supplierService.listByPage(supplierName, page);
        return Result.success(result);
    }

    @DeleteMapping("/deleteById")
    @ApiOperation("根据id删除供应商")
    public Result deleteById(Long id) {
        supplierService.deleteById(id);
        return Result.success();
    }

    /**
     * 计算收益
     * @param id 供应商id
     * @param pluginId 插件id
     * @return
     */
    @GetMapping("/getMoney")
    @ApiOperation("计算收益")
    public Result getMoney(Long id, Long pluginId) {
        BigDecimal money = supplierService.getMoney(id, pluginId);
        return Result.success(money.doubleValue());
    }
}
